<?php
/**
 * Data Model
 *
 * @property Data $ParentData
 * @property Data $ChildData
 */
class WxSubscribe extends WechatAppModel {

/**
 * Use table
 *
 * @var mixed False or table name
 */
	public $useTable = 'wechat_subscribe';
	
	public function add($data){
		$dsave = array(
				'openid'=>$data['FromUserName'],
				'CreateTime'=>$data['CreateTime'],
				'event'=>$data['Event'],
		);
		return $this->save($dsave);
	}
	
	public function substate($openid = false){
		$check = $this->find('first',array(
			'conditions'=>array(
				'WxSubscribe.openid'=>$openid
			),
			'order'=>'WxSubscribe.CreateTime DESC'
		)); 
		if($check){
			if($check['WxSubscribe']['event'] == 'subscribe'){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
	
	public function firstSubscribe($openid = false){
		$count = $this->find('count',array(
			'conditions'=>array(
				'WxSubscribe.openid'=>$openid,
				'WxSubscribe.event'=>'subscribe',
			),
		));
		if($count ==1){
				
		}
	}
}
